<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>物流公司信息</title>
    <link rel="stylesheet" href="/js/elementui/index.css">
    <script src="/js/vue/vue.js"></script>
    <script src="/js/axios/axios.min.js"></script>
    <script src="/js/qs/qs.min.js"></script>
    <!-- 引入组件库 -->
    <script src="/js/elementui/index.js"></script>
</head>
<body>


<div id="app">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="物流公司名称">
            <el-input v-model="formInline.logisticsName" placeholder="输入物流公司名称"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
    </el-form>

    <el-button type="primary" @click="openDialog" >添加物流公司</el-button>

    <!--数据表格-->
    <el-table
            :data="logistics"
            style="width: 100%">
        <el-table-column label="物流公司编号" width="310">
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.logisticsId }}</span>
            </template>
        </el-table-column>
        <el-table-column label="物流公司名称" width="170">
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.logisticsName }}</span>
            </template>
        </el-table-column>
        <el-table-column label="负责人" width="85">
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.principal }}</span>
            </template>
        </el-table-column>
        <el-table-column label="联系方式" width="140">
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.logisticsContact }}</span>
            </template>
        </el-table-column>
        <el-table-column label="运营区域" width="110">
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.area }}</span>
            </template>
        </el-table-column>
        <el-table-column label="加入时间" width="190">
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.joinTime }}</span>
            </template>
        </el-table-column>
        <el-table-column label="价格(元/每吨)" width="100">
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.price }}</span>
            </template>
        </el-table-column>


        <el-table-column label="操作" width="170">
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>

    <!--分页-->
    <el-pagination
            background
            layout="prev, pager, next"
            :total="total"
            @current-change="loadPage"
            :current-page="current"
            :page-size="pageSize">
    </el-pagination>


    <!--增加修改弹出层-->

    <!-- 修改弹窗 -->
    <el-dialog title="物流公司信息" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <el-form-item label="公司名称：" :label-width="formLabelWidth">
                <el-input v-model="form.logisticsName" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="form">
            <el-form-item label="负责人：" :label-width="formLabelWidth">
                <el-input v-model="form.principal" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="form">
            <el-form-item label="联系方式：" :label-width="formLabelWidth">
                <el-input v-model="form.logisticsContact" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="form">
            <el-form-item label="运营区域：" :label-width="formLabelWidth">
                <el-input v-model="form.area" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="form">
            <el-form-item label="价格(元/每吨)：" :label-width="formLabelWidth">
                <el-input v-model="form.price" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="form">
            <el-form-item label="备注：" :label-width="formLabelWidth">
                <el-input type="textarea"  v-model="form.remarks" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>

        <div slot="footer" class="dialog-footer">
            <el-button @click="cancelDialog">取 消</el-button>
            <el-button type="primary" @click="saveDialog" >确 定</el-button>
        </div>
    </el-dialog>


</div>
</body>
<script>


    new Vue({
        el: "#app",
        data(){
            return{
                //---分页
                current:1,//当前页数
                total:0, //总条数
                pageSize:10 ,//每页条数
                logistics:null,//数据信息
                formInline: {
                    logisticsName: ''
                },
                dialogFormVisible: false,
                form:{
                    logisticsName: "",
                    principal: "",
                    logisticsContact: "",
                    area: "",
                    price: "",
                    remarks: "",
                },
                formLabelWidth: '120px'
            }
        },
        mounted(){
            this.loadPage(1);
        },
        methods:{
            onSubmit() {
                this.loadPage(1);
            },
            handleEdit(index, row) {
                this.form = row;
                this.dialogFormVisible = true;
            },
            handleDelete(index, row) {
                this.deleteLogistics(row.logisticsId);
            },
            //跳转当前页
            loadPage(current) {
                this.current = current;
                this.logisticsName=this.formInline.logisticsName;
                //查询
                axios.get("/logistics?current="+current+"&logisticsName="+this.logisticsName).then(value => {
                    this.logistics = value.data.data.records;
                    this.total = value.data.data.total;
                    this.pageSize=value.data.data.size;
                    this.current=value.data.data.current;
                })
            },
            //清空弹窗内容
            clearDialog(){
                this.form={
                    logisticsId:"",
                    logisticsName: "",
                    principal: "",
                    logisticsContact: "",
                    area: "",
                    price: "",
                    remarks: "",
                }
            },
            //打开弹窗
            openDialog(){
                this.clearDialog();
                this.dialogFormVisible = true;
            },
            //弹窗取消按钮
            cancelDialog(){
                this.loadPage(this.current);
                this.clearDialog();
                this.dialogFormVisible = false;
            },
            //弹窗提交方法
            saveDialog() {
                if (this.form.logisticsId == "") {
                    //增加
                    axios.post("/logistic",this.form
                        ).then(value => {
                        if (value.data.code == 1) {
                            this.loadPage(this.current);
                        }
                    });
                } else {
                    //修改
                    axios.put("/logistic",this.form
                    ).then(value => {
                        if (value.data.code == 1) {
                            this.loadPage(this.current);
                        }
                    })
                }
                this.clearDialog();
                this.dialogFormVisible = false;
            },
            //删除
            deleteLogistics(id) {
                this.$confirm('此操作将永久删除该条信息, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.delete("/logistic/" + id
                    ).then(value => {
                        if (value.data.code == 1) {
                            this.loadPage(this.current);
                        }
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }

        }
    })

</script>

</html>